package com.cat.dynamicPlanning;

/**
*   @description https://leetcode.cn/problems/jump-game-iii/
*   @author 曲大人的喵
*   @create 2025/9/4 23:38
*   @since JDK17
*/

public class Solution74 {
    boolean ans;
    int n;
    int[] vis;
    public void dfs(int[] arr, int cur) {
        vis[cur] = 1;
        if (arr[cur] == 0) {
            ans = true;
            return;
        }

        if (arr[cur] + cur < n && vis[arr[cur] + cur] != 1) {
            dfs(arr, cur + arr[cur]);
        }
        if (cur - arr[cur] >= 0 && vis[cur - arr[cur]] != 1) {
            dfs(arr, cur - arr[cur]);
        }

    }

    public boolean canReach(int[] arr, int start) {
        n = arr.length;
        vis = new int[n];
        dfs(arr, start);
        return ans;
    }
}
